package com.project.personalfundmanager.client.taxitems;

import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.project.personalfundmanager.client.common.Const;
import com.project.personalfundmanager.shared.models.TaxableIncomeModel;

public class IncomeItem extends ParentItem<TaxableIncomeModel>
{
	public IncomeItem( TaxableIncomeModel model )
	{
		super( model );
	}

	@Override
	public void addFormComponents( FormPanel formPanel, boolean isEditable )
	{
		addToPanel( formPanel, uiHelper.getNumberField( "Basic Salary", Const.BASIC_SALARY, isEditable ) );
		addToPanel( formPanel, uiHelper.getNumberField( "HRA", Const.HRA, isEditable ) );
		addToPanel( formPanel, uiHelper.getNumberField( "Conveyence", Const.CONVEYANCE, isEditable ) );
		addToPanel( formPanel, uiHelper.getNumberField( "Other Allowances", Const.OTHER_INCOME, isEditable ) );
	}

	@Override
	public void addTotalComponents( FormPanel totalPanel )
	{
		addToPanel( totalPanel, uiHelper.getNumberField( "Total", Const.TOTAL_INCOME, false ) );
	}

	public void calculateTotal()
	{
		int total = model.getBasicSalary() + model.getHRA() + model.getConveyance() + model.getOtherIncome();
		model.setTotal( total );
	}
}
